<template>
  <div>
    <h3>名称: {{title}}</h3>
    <el-form label-width="80px" class="demo-ruleForm">
      <el-form-item label="描述：">
        输入开始（yyyyMMdd）和结束时间（yyyyMMdd），逗号隔开
      </el-form-item>
      <el-form-item label="输入：">
        <el-input v-model="dateInput" style="width:500px"  placeholder="如：20200101,20200201"></el-input>
      </el-form-item>
      
      <el-form-item>
        <el-button type="primary" v-if="showBtn" @click="onSubmit">执行</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import apiRedoReportLog from "@/api/logManage/redoReportLog";
export default {
  name: "redoReportLogOrderReport",
  props:{
        title: { //父组件 查询对象
          type: String,
          default: ""
        }
  },
  data() {
    return { 
      dateInput:'',
      showBtn:true
    };
  },
  methods: {
    onSubmit(){
      this.showBtn = false
      setTimeout(() => {
        this.showBtn = true
      },800)
      
      if(!this.dateInput){
        this.$message.error('未输入时间')
        return
      }
      let arr = this.dateInput.split(',')
      if(arr.length!=2){
        this.$message.error('输入错误')
        return 
      }
      let startDate = arr[0].trim(), endDate=arr[1].trim()
      if(startDate.length!=8 || endDate.length!=8 ){
        this.$message.error('日期格式输入错误')
        return  
      }
      if(parseInt(endDate) - parseInt(startDate) < 0){
        this.$message.error('结束日期不能大于开始日期')
        return   
      }

      apiRedoReportLog.syncOrderReport(startDate,endDate).then(res=>{
        this.$message.success('已提交后台执行')  
      })
    }
  }
};
</script>
